package com.mixsmart.spellsql.where.exp;

import com.mixsmart.spellsql.IExpression;
import com.mixsmart.spellsql.where.CompositeWhere;
import com.mixsmart.utils.StringUtils;

/**
 * Between 表达式；如：age between 20 and 30
 * @author lmq  2019年1月23日
 * @version 1.0
 * @since 1.0
 */
public class BetweenExpression extends CompositeWhere implements IExpression {

    private String fieldName;
    
    private Object startValue;
    
    private Object endValue;
    
    public BetweenExpression(String fieldName, Object startValue, Object endValue) {
        this.fieldName = fieldName;
        this.startValue = startValue;
        this.endValue = endValue;
    }

    @SuppressWarnings("unchecked")
    @Override
    public String build() {
        String fieldNameTmp = StringUtils.firstToUppercase(fieldName);
        String startName = "start" + fieldNameTmp;
        String endName = "end" + fieldNameTmp;
        super.addParameter(startName, this.startValue);
        super.addParameter(endName, this.endValue);
        return fieldName + " between :"+ startName +" and :" + endName;
    }
    
}
